package com.diy.sigmund.diyuser.test.controller;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.entity.po.user.UserAuth;
import com.diy.sigmund.diycommon.spring.anno.IgnoreTokenVerification;
import com.diy.sigmund.diyuser.mapper.UserAuthMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * https://www.cnblogs.com/cjsblog/p/9372258.html
 * https://www.cnblogs.com/xiaotong1223/p/9201614.html
 * https://blog.csdn.net/houysx/article/details/80229991
 *
 * @author ylm-sigmund
 * @since 2021/9/6 17:33
 */
@RestController
@RequestMapping("/user/pageHelperTest")
public class PageHelperTestController {

    @Autowired
    private UserAuthMapper userAuthMapper;

    @IgnoreTokenVerification
    @PostMapping("/select/{pageNum}")
    public ResultMsg select(@PathVariable int pageNum) {
        //  在你需要进行分页的 MyBatis 查询方法前调用 PageHelper.startPage 静态方法即可，紧跟在这个方法后的第一个MyBatis 查询方法会被进行分页。
        //  只要你可以保证在 PageHelper 方法调用后紧跟 MyBatis 查询方法，这就是安全的
        PageHelper.startPage(pageNum, 3);
        // page类型的对象
        List<UserAuth> userAuths = userAuthMapper.listByTestPageHelper();
        // 封装返回对象，可再次自定义
        PageInfo<UserAuth> userAuthDOPageInfo = new PageInfo<>(userAuths);
        return ResultMsg.success(userAuthDOPageInfo);
    }
}
